<?php
	function imagesize($filename)
	{
		if (($size = @getimagesize($filename)) == true)
		{
			$W = $size[0];
			$H = $size[1];
			return $W.'x'.$H;
		}
		return "";
	}
	
	function deal ($dir)
	{
		echo '<h2>'.$dir.'</h2>';
		$tinydir = $dir."tiny/";
		$fulldir = $dir."full/";
		if (($dp = opendir($tinydir)) != false)
		{
			$list = array();
			while (($file = readdir($dp)) != false)
			{
				$path = $dir.$file;
				if ($file[0] != ".") // pas prendre . ni ..
				{
					if(is_dir($path))
						$listdir[] = $full;
					else
						$list[] = $file;
				}
			}
			closedir($dp);
			sort($list);
			foreach ($list as $file)
			{
				$tinypath = $tinydir.$file;
				$fullpath = $fulldir.$file;
				$img_size = imagesize($fullpath);
				$file_size = (int)(filesize($fullpath)/1024);
				$tiny_w = 140;
				$max_h = $tiny_w / 1.25 +6; /* +2 */
				echo '<div class="block">';
				echo '<table>';
				echo '<tr><td class="image" width="'.($tiny_w +2).'" height="'.$max_h.'">';
				echo '<a href="'.$fullpath.'" title="'.$file.'">';
				echo '<img src="'.$tinypath.'" class="wallpaper" alt="'.$file.'">';
				echo '</a>';
				echo '</td></tr>';
				echo '<tr><td class="sub">'.$img_size.' : '.$file_size.' ko</td></tr>';
				echo '</table>';
				echo '</div>';
			}
		}
		
		if(isset($listdir))
		{
			sort($listdir);
			foreach ($listdir as $full)
				deal($full.'/');
		}
	}
	
	deal("wallpapers/");
?>
